﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BacteriumBattle
{

    class Observer
    {
        //private Dictionary<int, Bacterium> Bacteria { get; set; }

        /// <summary>
        /// Adjacency Matrix: bacterium x bacterium = action
        /// </summary>
        private Dictionary<Bacterium, 
                           Dictionary<Bacterium, 
                                      BacteriumAction>> BattlefieldMap { get; set; }


        public Observer()
        {
            BattlefieldMap = new Dictionary<Bacterium, Dictionary<Bacterium, BacteriumAction>>();
        }

        public void RegisterOnBattlefield(Bacterium b)
        {
            if (!BattlefieldMap.ContainsKey(b))
            {
                BattlefieldMap.Add(b, new Dictionary<Bacterium, BacteriumAction>());
            }
            
            //DisplayBattlefield();
        }

        public void UpdateProperty()
        {
            //DisplayBattlefield();
        }

        public void DisplayBattlefield()
        {
            foreach (var b in BattlefieldMap.Keys)
            {
                foreach (var prop in typeof(Bacterium).GetProperties())
                {
                    Console.Write("{0}: {1} ", prop.Name, prop.GetValue(b, null));
                }
                Console.WriteLine();
            }
            Console.WriteLine("---------------------------------------------------------------------------------------------");
        }

        public List<Bacterium> GetNeighbors(Bacterium b)
        {
            return new List<Bacterium>(BattlefieldMap.Keys.Where(p => p.ID != b.ID));
        }
    }
}
